#!/usr/bin/env python
# coding: utf-8

import urllib
import urllib2
import mimetools

from msgpack import packb, unpackb

input = {'vcheck': 1, 'user_id': 100059076, '_os': 'i', 'd_ver': '0.0.186', 'token': '1988866', 'app_ver': '2.4.3', 'user_stage_open':True}
FILE_PATH = r"/Users/monstar-216/Downloads/100059076.txt"

def request_add_file(request, filename, data):
        boundry = mimetools.choose_boundary()
        print '________boundry',boundry
        body = '''
--%s
Content-Disposition: file; name="data"; filename="%s"
Content-Type: text/plain
    
%s
--%s--
''' % (boundry, filename, data, boundry)
        print '________boundry',boundry
        request.add_header('Content-type', 'multipart/form-data; boundary=%s' % boundry)
        request.add_header('Content-length', len(body))
        request.add_data(body)
        return request
if __name__ == '__main__':
    url = 'http://192.168.10.237/special_stage/place/1/time/3'
    request = urllib2.Request(url)
    #filedata = packb(input)
    f = open(FILE_PATH, 'rb')
    filedata = f.read()
    f.close()
    
    request_add_file(request, '100059076.txt', filedata)
    res = urllib2.urlopen(request).read()
    print res
